package concept.misc;

import java.util.ArrayList;
import java.util.List;

class Output
{
	private List<String> response;
	private String message;
	
	public Output()
	{
		response = new ArrayList<String>();
		response.add("message0");
		response.add("message1");
		response.add("message2");
	}
	
	List<String> getRawResponse()
	{
		return response;
	}
	
	public void setMessage(String msg)
	{
		this.message = msg;
	}
	
	public String getMessage()
	{
		return this.message;
	}
	
	public String toString()
	{
		return String.format("output = %s", getRawResponse());
	}
}

class OutputProcessor
{
	void doOutput(Output output)
	{
		output.getRawResponse().set(0, "header");
	}
}

class StringArrayEater
{
	String[] s;
	StringArrayEater(String... s)
	{
		this.s = s;
	}
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		for(String s:this.s)
		{
			sb.append(s+" ");
		}
		return sb.toString().trim();
	}
}

class StringEater
{
	String s;
	StringEater(String s)
	{
		this.s = s;
	}
	public String toString()
	{
		return s;
	}
}

class ForwardReference
{
	int x = getY();
	int y = 5;
	int getY()
	{
		return y;
	}
}

public class ReferenceLab
{
	static void doOutput()
	{
		Output output = new Output();
		OutputProcessor processor = new OutputProcessor();
		
		System.out.println(output);
		processor.doOutput(output);
		System.out.println(output);
		
		output.setMessage("Hello!");
		Output another = output;
		another.setMessage("Kunichiwa");
		System.out.println(output.getMessage());
	}
	static void doStringArray()
	{
		String[] s = new String[]{"1","2","3"};
		StringArrayEater sae = new StringArrayEater(s);
		System.out.println(sae);
		s = new String[]{"a","b","c"};
		System.out.println(sae);
		s[0]=new String("A");
		s[1]="B";
		s[2]="C";
		System.out.println(sae);
		
		String ss[] = s;
		System.out.println(ss[0]);
		s[0] = "AAA";
		System.out.println(ss[0]);
	}
	static void doString()
	{
		String s = "1";
		StringEater se = new StringEater(s);
		System.out.println(se);
		s = "a";
		System.out.println(se);
	}
	static void doForwardReferencing()
	{
		ForwardReference fr = new ForwardReference();
		System.out.println(fr.x);
	}
	public static void main(String[] args)
	{
		//doOutput();
		//doStringArray();
		//doString();
		doForwardReferencing();
	}
}
